package com.dingding.manager.modules.system.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.shiro.authc.AuthenticationException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dingding.manager.common.beans.sys.SysMenu;
import com.dingding.manager.common.vo.MenuNode;
import com.dingding.manager.core.shiro.ShiroKit;
import com.dingding.manager.core.shiro.ShiroUser;
import com.dingding.manager.modules.system.service.IResourceService;

/**
 * @Description 资源相关控制器
 * @author fengshuonan
 * @date 2016年12月6日 上午10:49:18
 */
@RestController
@RequestMapping("/resource")
public class ResourceController {

	@Resource
	IResourceService resourceService;
	
	/**
	 * @Description 获取所有菜单
	 * @author fengshuonan
	 */
	@RequestMapping("/list")
	public MenuNode menus(){

		ArrayList<Integer> arrayList = new ArrayList<Integer>();
		ShiroUser user = ShiroKit.getUser();
		if(user == null){
			throw new AuthenticationException();
		}
		List<Integer> roleList = user.getRoleList();
		for (int i = 0; i < roleList.size(); i++) {
			arrayList.add(roleList.get(i));
		}
		MenuNode menuNode = resourceService.getMenuNode(arrayList);
		return menuNode;
	}
	
	/**
	 * @Description: 获取所有资源集合（角色授权菜单tree）
	 * @date 2016年12月16日 下午4:28:40
	 * @author SUNZHICHENG 
	 * @since V2.6.2
	 */
	@RequestMapping(value="/menuList")
	public List<SysMenu> getMenuList(){
		return resourceService.getMenuList();
	}
	
}
